#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;

namespace cx
{
	class string
	{
	public:

		string(const char* str = "");
		string(const string& s);
		string& operator=(const string& s);
		~string();

		const char* c_str();

	private:

		char* _str = nullptr;

	};

	string::string(const char* str)
	{
		char* tmp = new char[strlen(str) + 1];
		strcpy(tmp, str);
		_str = tmp;
	}

	string::string(const string& s)
	{
		char* tmp = new char[strlen(s._str) + 1];
		strcpy(tmp, s._str);
		_str = tmp;
	}

	string& string::operator=(const string& s)
	{
		if (this != &s)
		{
			delete[] _str;
			char* tmp = new char[strlen(s._str) + 1];
			strcpy(tmp, s._str);
			_str = tmp;
		}
		return *this;
	}

	string::~string()
	{
		delete[] _str;
		_str = nullptr;
	}

	const char* string::c_str()
	{
		return _str;
	}


}

int main()
{
	cx::string s = "hello";
	cx::string s1(s);
	cx::string s2;
	s2 = s;

	s = "xixi";
	s1 = "haha";
	s2 = "hehe";
	cout << s.c_str() << endl;
	cout << s1.c_str() << endl;
	cout << s2.c_str() << endl;


	return 0;
}